package com.sx.micowell.module.member

import android.text.SpannableString
import android.text.Spanned
import android.text.style.StrikethroughSpan
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.miloyu.modelnet.response.MemberSetMealVO
import com.sx.micowell.R

/**
 * @Author: YY
 * @Time: 2021/8/20
 * @Describe 会员套餐 列表适配器
 */
class MemberSetMealListAdapter : BaseQuickAdapter<MemberSetMealVO, BaseViewHolder>(R.layout.item_member_list) {

    var clickId: Int = 0

    override fun convert(holder: BaseViewHolder, item: MemberSetMealVO) {
        holder.setText(R.id.tv_title, item.name)
        holder.setText(R.id.tv_discount, "¥${item.money}")
        holder.setText(R.id.tv_original_cost, setDeleteLine("原价¥${item.oldMoney}"))

        holder.setBackgroundResource(R.id.layout1, R.drawable.shape_gradual_change1)

        if (clickId == holder.adapterPosition) {
            holder.setBackgroundResource(R.id.layout1, R.drawable.shape_gradual_change8)
        }
    }

    /**
     * 删除线
     */
    private fun setDeleteLine(value: String): SpannableString {
        val sStr = SpannableString(value)
        sStr.setSpan(StrikethroughSpan(), 0, value.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        return sStr
    }
}